from SendInput import Keyboard, Mouse
import time
import pydirectinput
import pyautogui
import os
import tkinter as tk
from tkinter import ttk

def setKepdown (val) :
    for letter in val:     # 第一个实例
        if (letter.isupper()) :
            # pydirectinput.press(letter)
            pydirectinput.keyDown('shift')
            pydirectinput.keyDown(letter.lower())
            pydirectinput.keyUp(letter.lower())
            pydirectinput.keyUp('shift')
        elif letter == '@':
            pydirectinput.keyDown('shift')
            pydirectinput.keyDown('2')
            pydirectinput.keyUp('2')
            pydirectinput.keyUp('shift')
        else :
            pydirectinput.press(letter)

def moveClick (x, y):
    time.sleep( 0.1 )
    Mouse.move(x, y, True)
    time.sleep( 0.1 )
    Mouse.leftClick()
    time.sleep( 0.1 )
    return

def moveANClick (x, y):
    time.sleep( 0.1 )
    Mouse.move(x, y, True)
    time.sleep( 0.1 )
    Mouse.leftDown()
    time.sleep( 0.5 )
    Mouse.leftUp()
    time.sleep( 0.1 )
    return

def moveRightClick (x, y):
    time.sleep( 0.1 )
    Mouse.move(x, y, True)
    time.sleep( 0.1 )
    Mouse.rightClick()
    time.sleep( 0.1 )
    return

def colsetan () : 
    time.sleep( 0.1 )
    Mouse.move(459, 9, True)
    time.sleep( 0.1 )
    Mouse.leftClick()
    time.sleep( 0.1 )
    return

def closeSuer (): 
    bool = True
    try:
        close_icon = os.path.join('closeSure.png')
        Part = pyautogui.locateOnScreen(close_icon, region=(1181, 627, 200, 200), confidence=0.7)
        moveClick(pyautogui.center(Part).x, pyautogui.center(Part).y)
    except pyautogui.ImageNotFoundException:
        print("未找到指定的图像")
    return bool

def stops (): 
    bool = True
    try:
        close_icon = os.path.join('jieju.png')
        Part = pyautogui.locateOnScreen(close_icon, region=(992, 245, 800, 600), confidence=0.7)
        moveClick(pyautogui.center(Part).x, pyautogui.center(Part).y + 130)
    except pyautogui.ImageNotFoundException:
        print("未找到指定的图像")
    return bool
   
def getHuShouShangRen (): 
    bool = []
    try:
        close_icon = os.path.join('aoen.png')
        Part = pyautogui.locateOnScreen(close_icon, region=(453, 151, 1800, 950), confidence=0.6)
        return [pyautogui.center(Part).x, pyautogui.center(Part).y]
    except pyautogui.ImageNotFoundException:
        print("未找到指定的图像")
    return []



# 创建主窗口
root = tk.Tk()
root.title("魔域脚本")
root.geometry("1200x600")

# 天使孵化插件
frame1 = tk.Frame(root)
frame1.pack(pady=5)

label1 = tk.Label(frame1, text="天使孵化 孵化数量:")
label1.pack(side=tk.LEFT, padx=5)

entry = tk.Entry(frame1, width=20)
entry.insert(0, "30")
entry.pack(side=tk.LEFT, padx=5)


label2 = tk.Label(frame1, text="选择:")
label2.pack(side=tk.LEFT, padx=5)

options = ["男天使", "女天使"]
combobox = ttk.Combobox(frame1, values=options, state="readonly")
combobox.set("男天使")  # 默认显示文字
combobox.pack(side=tk.LEFT, padx=5)

# 创建按钮
button = tk.Button(frame1, text="运行", command=lambda: fuhuabb(entry.get(), combobox.get()))
button.pack(side=tk.LEFT, padx=5)

# 孵化bb33个
def fuhuabb (val, val1):
    colsetan()
    sum = int(val)/6 if int(val)/6 % 1 == 0 else int(int(val)/6) + 1
    print(sum)
    for i in range(int(sum)):
        for i in range(6):
            time.sleep( 0.2 )
            setKepdown('1')
            time.sleep( 0.2 )
            if (val1 == '男天使'):
                moveClick(1118, 634)
            else:
                moveClick(1103, 677)
        moveClick(2349, 438)
        time.sleep( 0.2 ) 
        for i in range(12):
            moveRightClick(2392, 425)

# 合太古插件
frame2 = tk.Frame(root)
frame2.pack(pady=5)
label2 = tk.Label(frame2, text="合太古 左边数量:")
label2.pack(side=tk.LEFT, padx=5)
entry2 = tk.Entry(frame2, width=20)
entry2.insert(0, "5")
entry2.pack(side=tk.LEFT, padx=5)
label21 = tk.Label(frame2, text="右边数量:")
label21.pack(side=tk.LEFT, padx=5)
entry21 = tk.Entry(frame2, width=20)
entry21.insert(0, "5")
entry21.pack(side=tk.LEFT, padx=5)
# 创建按钮
button2 = tk.Button(frame2, text="运行", command=lambda: joinTaigu(entry2.get(), entry21.get()))
button2.pack(side=tk.LEFT, padx=5)

def joinTaigu (left, right):
    colsetan()
    for i in range(int(left)):
        moveClick(2352, 219)
        time.sleep( 0.3 )
        moveClick(2352, 219)
        time.sleep( 0.3 )
        moveRightClick(2272, 279)
        time.sleep( 0.3 )
        moveClick(140, 532)
        if (i != (int(left) - 1)) :
            time.sleep( 0.3 ) 
            moveClick(2224, 222)
            time.sleep( 0.3 )
            moveClick(1224, 771) 
    setKepdown('p')   
    time.sleep( 0.2 )  
    setKepdown('p')   
    time.sleep( 0.3 )
    moveClick(2224, 222)
    time.sleep( 0.3 )
    moveClick(1224, 771)    
    time.sleep( 0.3 )
    for i in range(int(right)):
        moveClick(2377, 218)
        time.sleep( 0.3 )
        moveClick(2377, 218)
        time.sleep( 0.3 )
        moveRightClick(2272, 279)
        time.sleep( 0.3 )
        moveClick(140, 532)
        if (i != (int(right) - 1)) :
            time.sleep( 0.3 )
            moveClick(2224, 222)
            time.sleep( 0.3 )
            moveClick(1224, 771)  




# 打开幻兽精华6星o
frame3 = tk.Frame(root)
frame3.pack(pady=5)
label3 = tk.Label(frame3, text="打开幻兽精华6星o 打开数量:")
label3.pack(side=tk.LEFT, padx=5)
entry3 = tk.Entry(frame3, width=20)
entry3.insert(0, "10")
entry3.pack(side=tk.LEFT, padx=5)
# 创建按钮
button3 = tk.Button(frame3, text="运行", command=lambda: openBeast6(entry3.get()))
button3.pack(side=tk.LEFT, padx=5)
def openBeast6 (val):
    colsetan()
    for i in range(int(val)):
        time.sleep( 0.2 )
        setKepdown('1')
        time.sleep( 0.2 )
        moveClick(1100, 589)
        time.sleep( 0.2 )
        moveClick(1120, 590)


# 喂合单o型等级
frame4 = tk.Frame(root)
frame4.pack(pady=5)
label4 = tk.Label(frame4, text="喂合单o型等级 喂食数量:")
label4.pack(side=tk.LEFT, padx=5)
entry4 = tk.Entry(frame4, width=20)
entry4.insert(0, "9")
entry4.pack(side=tk.LEFT, padx=5)
# 创建按钮
button4 = tk.Button(frame4, text="运行", command=lambda: feedBeast(entry4.get()))
button4.pack(side=tk.LEFT, padx=5)
def feedBeast (val):
    colsetan()
    moveClick(2224, 390)
    moveClick(1224, 771)
    time.sleep( 0.3 )
    moveClick(1113, 91)
    time.sleep( 0.2 )
    for i in range(int(val)):
        moveClick(2224, 303)
        moveClick(1224, 771)
        time.sleep( 0.3 )
        moveClick(1113, 91)
        time.sleep( 0.2 )

# 购买幻化幸运草
frame5 = tk.Frame(root)
frame5.pack(pady=5)
label5 = tk.Label(frame5, text="购买幻化幸运草，购买数量:")
label5.pack(side=tk.LEFT, padx=5)
entry5 = tk.Entry(frame5, width=20)
entry5.insert(0, "100")
entry5.pack(side=tk.LEFT, padx=5)
# 创建按钮
button5 = tk.Button(frame5, text="运行", command=lambda: getCaoValue(entry5.get()))
button5.pack(side=tk.LEFT, padx=5)
def getCaoValue (val):
    colsetan()
    sum = int(val) * 2
    for i in range(sum):
        moveRightClick(904, 519)

# 购买恒金石圣兽魔金
frame6 = tk.Frame(root)
frame6.pack(pady=5)
# 创建按钮
button6 = tk.Button(frame6, text="购买恒金石圣兽魔金", command=lambda: getHengJinMo())
button6.pack(side=tk.LEFT, padx=5)
def getHengJinMo ():
    colsetan()
    moveClick(942, 1361)
    time.sleep( 0.2 )
    moveClick(842, 985)
    time.sleep( 0.2 )
    moveClick(1376, 982)
    time.sleep( 0.2 )
    moveRightClick(1250, 683)
    time.sleep( 0.2 )
    moveClick(1473, 599)
    time.sleep( 0.2 )
    moveClick(1400, 694)
    time.sleep( 0.2 )
    moveClick(1776, 458)


# 购买30个奥恩 并放入孵化所
button7 = tk.Button(frame6, text="购买奥恩并孵化", command=lambda: getAo30AndFH())
button7.pack(side=tk.LEFT, padx=5)
def getAo30AndFH ():
    colsetan()
    time.sleep( 1 )
    list = getHuShouShangRen()
    if (len(list) == 2) :
        time.sleep( 0.1 )
        Mouse.move(list[0] + 6, list[1] + 71, True)
        time.sleep( 1 )
        Mouse.leftClick()
        time.sleep( 0.2 )
        moveClick(1078, 620)
        time.sleep( 0.2 )   
        for i in range(60):
            moveRightClick(943, 523)  
        moveClick(1013, 488) 
        time.sleep( 1 )  
        setKepdown('i') 
        time.sleep( 0.2 )   
        setKepdown('p') 
        time.sleep( 1 )
        moveClick(2350, 454) 
        time.sleep( 0.2 )
        for i in range(5):
            for k in range(12):
                moveRightClick(2197, 859) 
            for i in range(12):
                moveRightClick(2392, 425)

# 一建合10次太古
def setTenTime ():
    getHengJinMo()
    setKepdown('p')
    time.sleep( 0.2 ) 
    moveClick(2496, 474) 
    time.sleep( 0.2 ) 
    feedBeast(9)
    time.sleep( 0.2 )
    moveClick(2538, 474) 
    time.sleep( 0.2 )
    joinTaigu(5, 5)
button8 = tk.Button(frame6, text="一建合10次太古", command=lambda: setTenTime())
button8.pack(side=tk.LEFT, padx=5)     


# 运行主循环
root.mainloop()




# listen_for_input()